jQuery.noConflict();
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
    return vars;
}

function validate_field_configActive(){
    var title = jQuery("#titleofActivi").val();

    if(title.length == 0 || title == null){
        setVisiableDiv_Activity_alert_warning("Title is required");
        return false;
    }
    if(title.length > 30){
        setVisiableDiv_Activity_alert_warning("Title just have less than 30 character");
        return false;
    }
  
    var address = jQuery("#addressOfActivi").val();
    if(address.length == 0 || address == null){
        setVisiableDiv_Activity_alert_warning("Address is required");
        return false;
    }
    var time_start = jQuery("#timeStartofActivi").val();
    if(time_start.length == 0 || time_start == null){
        setVisiableDiv_Activity_alert_warning("Time Start is required");
        return false;
    }
    var time_end = jQuery("#timeEndofActivi").val();
    if(time_end.length == 0 || time_end == null){
        setVisiableDiv_Activity_alert_warning("Time End is required");
        return false;
    }
  
  
    var max_people = jQuery("#limitedAccessofActivi").val();
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    if(max_people.length == 0 || max_people == null){
        setVisiableDiv_Activity_alert_warning("Max People is required");
        return false;
    }
    if(max_people == 0){
        setVisiableDiv_Activity_alert_warning("Max People is invalid");
        return false;
    }
    if(!numericReg.test(max_people)){
        setVisiableDiv_Activity_alert_warning("Max People must have a number only");
        return false;
    }
    var sendTO = jQuery("#sendToofActivi").val();
    if(sendTO.length == 0 || sendTO == null){
        setVisiableDiv_Activity_alert_warning("Send to is required");
        return false;
    }
    var description = jQuery("#descripofActivi").val();
    if(description.length == 0 || description == null){
        setVisiableDiv_Activity_alert_warning("Description is required");
        return false;
    }

    var timeS = getTime(time_start);
   
    var timeE = getTime(time_end);
    
    return compareHour(timeS, timeE);
  
}


function validate_field_EditActive(){
    var title = jQuery("#titleofActivi_edit").val();

    if(title.length == 0 || title == null){
        setVisiableDiv_Activity_alert_warning("Title is required");
        return false;
    }
    if(title.length > 30){
        setVisiableDiv_Activity_alert_warning("Title just have less than 30 character");
        return false;
    }
  
    var address = jQuery("#addressOfActivi_edit").val();
    if(address.length == 0 || address == null){
        setVisiableDiv_Activity_alert_warning("Address is required");
        return false;
    }
    var time_start = jQuery("#timeStartofActivi_edit").val();
    if(time_start.length == 0 || time_start == null){
        setVisiableDiv_Activity_alert_warning("Time Start is required");
        return false;
    }
    var time_end = jQuery("#timeEndofActivi_edit").val();
    if(time_end.length == 0 || time_end == null){
        setVisiableDiv_Activity_alert_warning("Time End is required");
        return false;
    }
  
  
    var max_people = jQuery("#limitedAccessofActivi_edit").val();
    var numericReg = /^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$/;
    if(max_people.length == 0 || max_people == null){
        setVisiableDiv_Activity_alert_warning("Max People is required");
        return false;
    }
    if(max_people == 0){
        setVisiableDiv_Activity_alert_warning("Max People is invalid");
        return false;
    }
    if(!numericReg.test(max_people)){
        setVisiableDiv_Activity_alert_warning("Max People must have a number only");
        return false;
    }
    var sendTO = jQuery("#sendToofActivi_edit").val();
    if(sendTO.length == 0 || sendTO == null){
        setVisiableDiv_Activity_alert_warning("Send to is required");
        return false;
    }
    var description = jQuery("#descripofActivi_edit").val();
    if(description.length == 0 || description == null){
        setVisiableDiv_Activity_alert_warning("Description is required");
        return false;
    }

    var timeS = getTime(time_start);
   
    var timeE = getTime(time_end);
    
    return compareHour(timeS, timeE);
  
}

function validate_Div_createSA(){
    var title = jQuery("#txtTitleSA").val(); 
    if(title.length == 0 || title == null){
        setVisiableDiv_createSA_alert_warning("Title is required");
        return false;
    }
    var description = jQuery("#txtDescripSA").val();
    if(description.length == 0 || description == null){
        setVisiableDiv_createSA_alert_warning("Description is required");
        return false;
    }
    var location = jQuery("#txtLocaSA").val();
    if(location.length == 0 || location == null){
        setVisiableDiv_createSA_alert_warning("Location is required");
        return false;
    }
    var day_start = jQuery("#SA_startdate").val();
    if(day_start.length == 0 || day_start== null){
        setVisiableDiv_createSA_alert_warning("Start date is required");
        return false;
    }
    var day_end = jQuery("#SA_enddate").val();
    if(day_end.length == 0 || day_end== null){
        setVisiableDiv_createSA_alert_warning("End date is required");
        return false;
    }
    if(parseDate(day_start).getTime() > parseDate(day_end).getTime()){
        setVisiableDiv_createSA_alert_warning("End date is invalid");
        return false;
    }
    var today = new Date();
    var dd = today.getDate();
    var mm = today.getMonth() + 1; // January is 0!

    var yyyy = today.getFullYear();
    if (dd < 10) {
        dd = '0' + dd;
    }
    if (mm < 10) {
        mm = '0' + mm;
    }
    var today = dd + '-' + mm + '-' + yyyy;
    var currentday = parseDate(today).getTime();
    
    if(parseDate(day_start).getTime() < currentday){
        setVisiableDiv_createSA_alert_warning("Start date is invalid");
        return false;
    }
    if(parseDate(day_end).getTime() < currentday){
        setVisiableDiv_createSA_alert_warning("Start date is invalid");
        return false;
    }
    return true;
}

function getTime(exam){
    var timeSplit = exam.split("-")[0];
   
    var hour = timeSplit.split(":")[0];
    var h = parseInt(hour, 10);
    if(exam.split("-")[1] == 'PM'){
        h = h + 12;
    }
    var timeReturn = h+":"+timeSplit.split(":")[1];
    //alert(timeReturn);
    return timeReturn;
}
function compareHour(start,end){
    var hour_start = parseInt(start.split(":")[0],10);
    var hour_end = parseInt(end.split(":")[0],10);
    //alert(hour_start +' to'+ hour_end);
    var minitues_start = start.split(":")[1];
    var minitues_end = end.split(":")[1];
    
    if(hour_end < hour_start){
        setVisiableDiv_Activity_alert_warning("Time End is invalid");
        return false;
    }
    if(hour_end == hour_start){
        if(minitues_start > minitues_end){
            setVisiableDiv_Activity_alert_warning("Time End is invalid");
            return false;
        }
    }
    return true;
}
function parseDate(str) {
    var mdy = str.split('/');
    return new Date(mdy[2], mdy[1], mdy[0]);
}
function cleardata_div_createSA(){
    jQuery("#txtTitleSA").val("");
    jQuery("#txtDescripSA").val("");
    jQuery("#txtLocaSA").val("");
    jQuery("#SA_startdate").val("");
    jQuery("#SA_enddate").val("");
}


